#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;


vector<int> dailyTemperatures(vector<int>& temperatures) {
    if (temperatures.size() == 1) return vector<int>{0};
    if (temperatures.size() == 2)
        return temperatures[1] > temperatures[0] ? vector<int>{1, 0}
                                                 : vector<int>{0, 0};
    int n = temperatures.size();
    unordered_map<int, int> temp;
    vector<int> ans(n);
    ans[n - 1] = 0;
    temp[temperatures[n - 1]] = n - 1;
    for (int i = n - 2; i >= 0; i--) {
        int early = 0x3f3f3f3f;
        for (int j = temperatures[i] + 1; j <= 100; j++) {
            if (temp.find(j) != temp.end()) {
                early = min(early, temp[j]);
            }
        }
        if (early == 0x3f3f3f3f)
            ans[i] = 0;
        else
            ans[i] = early - i;
        temp[temperatures[i]] = i;
    }
    return ans;
}

int main() {
    vector<int> temp{30,60,90};
    vector<int> a = dailyTemperatures(temp);
    for (int i = 0; i < a.size(); i++) cout << a[i] << ", ";
    return 0;
}